;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var router = require("../hash/pageRouter");
	var validate = require("validate");
	var databind = require("databind");
	var css_commissionGrade = require("./commissionGrade.css");
	var tools = require("tools");
	var html_createCommissionGrade = require("./html_createCommissionGrade.html");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var dialogCss = require("css_dialog");
	var tools = require("tools");
	var init = function() {
		initEvent();
		router.init();
		inquireSupplierCommissionGradePageList();
	};

	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		$("#commissionGrade .commissionGradeAdd").unbind("click").click(function() {
			$("#popdialog").html(html_createCommissionGrade);
			tools.inquireSystemParamByName($("#dialog_createCommissionGrade select[name=commissionGradeName]"), "佣金等级名称");
			tools.requireInput($("#dialog_createCommissionGrade"));
			dialog.showDialog($("#dialog_createCommissionGrade"));
			tools.loadSelectList($("#dialog_createCommissionGrade select[name=enterpriseId]"), "inquireEnterpriseList.json", "id", "name");
			
			tools.clearNoNum($("#dialog_createCommissionGrade input[name=annualRateStart]"), $("#dialog_createCommissionGrade input[name=expenseRate]"), $("#dialog_createCommissionGrade input[name=annualRateEnd]"));
			
			$("#dialog_createCommissionGrade .sure_yes").unbind("click").click(function(){
				databind.submitDom($("#dialog_createCommissionGrade"), function(){
					base.alert(1, "添加成功！");
					dialog.hideDialog($("#dialog_createCommissionGrade"));
					router.route("commissionGrade/commissionGrade.html");
				});
			});
			
			$("#dialog_createCommissionGrade .sure_no").unbind("click").click(function(){
				dialog.hideDialog($("#dialog_createCommissionGrade"));
			});
		});
		
		tools.inquireCurrentOperationList($("#commissionGrade"));
	};

	//查询列表
	var inquireSupplierCommissionGradePageList = function() {
		base.fnAjax({
			action: "inquireSupplierCommissionGradePageList.json",
			async: false, //同步异步
			nocode: false, //是否要登陆，true为不用登陆
			oData: {
				pageIndex: pageIndex,
				pageSize: pageSize
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#commissionGrade script").html();
					var html = juicer(tpl, data);
					$("#commissionGrade table").html(html);
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#commissionGrade .pagerCon"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireSupplierCommissionGradePageList();
						});
					
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	return {
		init: init
	};
});